package com.example.demo.Controller;
import com.example.demo.Enity.Activity;
import com.example.demo.dao.ActivityJpa;
import com.example.demo.dao.RelateJpa;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.ArrayList;
@RestController
@CrossOrigin(origins = "*", maxAge = 3600)
public class ActivityList {
    @Autowired
    ActivityJpa activityJpa;
    @Autowired
    RelateJpa relateJpa;
    @RequestMapping("/newgetActivity")
    public ArrayList newgetActivity(String fen){
        ArrayList a= new ArrayList<>();
        a = activityJpa.getIndexall(fen);
        return a;
    }
@RequestMapping("/getActivity")
    public ArrayList getActivity(String category){
    ArrayList a= new ArrayList<>();
    a = activityJpa.getCategoey(category);
    return a;
}
    @RequestMapping("/getActivity2")
    public ArrayList getActivity(String category,String findContent){
        ArrayList a= new ArrayList<>();
        a = activityJpa.getCategoey2(category,findContent);
        return a;
    }
    @RequestMapping("/getActivity3")
    public ArrayList getActivity3(String category,String id){
        ArrayList a= new ArrayList<>();
        a = activityJpa.getCategoey3(category,id);
        return a;
    }
//关注活动
@RequestMapping("/loveActivity")
public String loveActivity(String avid,String userid){
    relateJpa.addRelate(avid,userid);
    return "ok";
}
//取关活动
@RequestMapping("/deleteActivity")
public String deleteActivity(String avid,String userid){
    relateJpa.deleteRelate(avid,userid);
    return "ok";
}
//初始界面判断是否收藏
    @RequestMapping("/judgeActivity")
    public String judgeActivity(String avid,String userid){
    ArrayList a=new ArrayList();
    System.out.println(avid);
    System.out.println(userid);
    a=relateJpa.judgeActivity(avid,userid);
    System.out.println(a);
    if(a.size()==0){
        return "false";
    }
    else{
        return "true";
    }
    }
}
